package com.zhentao.controller;

import com.zhentao.model.common.admin.dto.AdminDictDataDto;
import com.zhentao.model.common.admin.dto.AdminDictTypeDto;
import com.zhentao.model.common.admin.pojo.DictData;
import com.zhentao.model.common.admin.pojo.DictType;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.service.DictDataService;
import com.zhentao.service.DictTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/dict")
public class AdminDictCotroller {
    @Resource
    private DictTypeService dictTypeService;

    @Resource
    private DictDataService dictDataService;

    /**
     * 字典表类型列表
     */
    @PostMapping("/adminDictTypeList")
    @ApiOperation("字典表类型列表")
    public ResponseResult adminDictTypeList(@RequestBody AdminDictTypeDto adminDictTypeDto){
        return dictTypeService.adminDictTypeList(adminDictTypeDto);
    }

    /**
     * 根据字典类型查询该类型下的数据
     */
    @PostMapping("/adminDictDataList")
    @ApiOperation("根据字典类型查询该类型下的数据")
    public ResponseResult adminDictDataList(@RequestBody AdminDictDataDto adminDictDataDto){
        return dictDataService.adminDictDataList(adminDictDataDto);
    }

    /**
     * 根据字典类型查询
     */
    @GetMapping("/adminDictDataSel")
    @ApiOperation("根据字典类型查询")
    public ResponseResult adminDictDataSel(String dictType){
        return dictDataService.adminDictDataSel(dictType);
    }

    /**
     * 字典类型---添加-修改-删除
     */
    @PostMapping("/adminCURDDictType")
    @ApiOperation("字典类型---添加-修改-删除")
    public ResponseResult adminAddDictType(@RequestBody DictType dictType){
        return dictTypeService.adminAddDictType(dictType);
    }

    /**
     * 字典数据表---添加-修改-删除
     */
    @PostMapping("/adminCURDDictData")
    @ApiOperation("字典数据表---添加-修改-删除")
    public ResponseResult adminCURDDictData(@RequestBody DictData dictData){
        return dictDataService.adminCURDDictData(dictData);
    }

    /**
     *
     * 根据字段表id查字典表类型id
     */
    @GetMapping("/adminDictDataById")
    @ApiOperation("根据字段表id查")
    public ResponseResult adminDictDataById(Integer dictDataId){
       return dictDataService.adminDictDataById(dictDataId);
    }
}